// Configure these parameters before you start.
var API_KEY = 'AIzaSyDdwq1wjTXlmfCARY1MG8TM2nvMoBExFzI';
var CLIENT_ID = '202554519670-27h6osg5cv7tcjt1p266pi8drfsvoog4.apps.googleusercontent.com';
var TABLE_ID = 'ga:84546033';
// Format of table ID is ga:xxx where xxx is the profile ID.

var dateMonthAgo = moment().subtract(30, 'days').format('YYYY-MM-DD');
var dateYesterday = moment().subtract(1, 'days').format('YYYY-MM-DD');

gadash.configKeys({
  'apiKey': API_KEY,
  'clientId': CLIENT_ID
});

function showCharts() {
	chartVisitors("chart-area");
}

function chartVisitors(div) {
	// Create a new Chart that queries visitors for the last 30 days and plots
	// visualizes in a line chart.
	var chart1 = new gadash.Chart({
	  'type': 'LineChart',
	  'divContainer': div,
	  'query': {
		'ids': TABLE_ID,
		'start-date': dateMonthAgo,
	    'end-date': dateYesterday,
		'metrics': 'ga:visitors,ga:visits,ga:pageviews',
		'dimensions': 'ga:date'
	  },
	  'chartOptions': {
		height:600,
		title: 'Bezoekers politie.nl (laatste 30 dagen)',
		hAxis: {title:'Datum'},
		vAxis: {title:'Aantal bezoekers'},
		curveType: 'function',
		fontSize: 24
	  }
	}).render();
	setTimeout('chartMobileDeviceInfo("chart-area")', 25000);
}

function chartMobileDeviceInfo(div) {
	// Create a new Chart that queries browsers of visitors for the last 30 days and plots
	// visualizes in a line chart.
	var chart1 = new gadash.Chart({
	  'type': 'PieChart',
	  'divContainer': div,
	  'last-n-days':30,
	  'query': {
		'ids': TABLE_ID,
		'metrics': 'ga:visitors',
		'sort': '-ga:visitors',
		'filters':'ga:visitors>10',
		'dimensions': 'ga:mobileDeviceInfo',
		'max-results': '10'
	  },
	  'chartOptions': {
		height:600,
		title: 'Mobiele Devices politie.nl (laatste 30 dagen)',
		hAxis: {title:'bezoekers'},
		vAxis: {title:'device'},
		curveType: 'function',
		fontSize: 24
	  }
	}).render();
	setTimeout('chartBrowserInfo("chart-area")', 15000);
}

function chartBrowserInfo(div) {
	// Create a new Chart that queries browsers of visitors for the last 30 days and plots
	// visualizes in a line chart.
	var chart1 = new gadash.Chart({
	  'type': 'BarChart',
	  'divContainer': div,
	  'last-n-days':30,
	  'query': {
		'ids': TABLE_ID,
		'metrics': 'ga:visitors',
		'sort': '-ga:visitors',
		'filters':'ga:visitors>10',
		'dimensions': 'ga:browser',
		'max-results': '10'
	  },
	  'chartOptions': {
		height:600,
		title: 'Browsers politie.nl (laatste 30 dagen)',
		hAxis: {title:'bezoekers'},
		vAxis: {title:'browser'},
		curveType: 'function',
		fontSize: 24
	  }
	}).render();
}